﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;


namespace IHISCETeim.Web.MachineSys.UserModel
{
    public partial class UClaimDemageControlSupplerDetailList : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "UClaimDemageControlList";
            }
        }
        #region 属性 (查询条件)


        protected string CommonFiled
        {
            get
            {
                return GetRequestValue<string>("CommonFiled", "");

            }
        }
        protected string CommonValue
        {
            get
            {
                return GetRequestValue<string>("CommonValue", "");

            }
        }

        protected string SupplerName
        {
            get
            {
                return GetRequestValue<string>("SupplerName", "");

            }
        }

        protected string DownlineDateFrom
        {
            get
            {
                return GetRequestValue<string>("DownlineDateFrom", "");

            }
        }
        protected string DownlineDateTo
        {
            get
            {
                if (string.IsNullOrEmpty(DownlineDateFrom))
                {
                    return "";
                }
                else
                {
                    string todate = GetRequestValue<string>("DownlineDateTo", "");
                    if (string.IsNullOrEmpty(todate))
                        return Convert.ToDateTime(DownlineDateFrom).AddDays(1).ToShortDateString();
                    else
                        return todate;
                }

            }
        }
        protected override string orderField
        {
            get
            {
                return string.IsNullOrEmpty(base.orderField) ? "ClaimsNumber" : base.orderField;
            }
        }
        protected override string orderDirection
        {
            get
            {
                return string.IsNullOrEmpty(base.orderDirection) ? "Desc" : base.orderDirection;
            }
        }
        #endregion
        protected DataTable SUMDT = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
            AddLog(Permission.查看, GetSQLWhere());
        }

        protected string GetSQLWhere()
        {
            string wheresql = "";
            string sqlcommonFiled = "";
            if (!string.IsNullOrEmpty(CommonValue))
            {
                sqlcommonFiled = QueryOperatorsEnumHelper.ConvertCommonOperator(CommonFiled, QueryOperatorsEnum.包含, CommonValue);
                wheresql = sqlcommonFiled;
            }

            string DOWNSQL = "";
            if (!string.IsNullOrEmpty(DownlineDateFrom))
            {
                DOWNSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("FaultDate", QueryOperatorsEnum.范围, DownlineDateFrom + "|" + DownlineDateTo);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + DOWNSQL;
                }
                else
                {
                    wheresql = DOWNSQL;
                }
            }

            string sqlAgentName = "";
            if (!string.IsNullOrEmpty(SupplerName))
            {
                sqlAgentName = QueryOperatorsEnumHelper.ConvertCommonOperator("SupplerName", QueryOperatorsEnum.包含, SupplerName);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + sqlAgentName;
                }
                else
                {
                    wheresql = sqlAgentName;
                }
            }

            return wheresql;
        }

        protected void DataBind()
        {



            DataTableCollection dts = UClaimDemageControlController.GetSupplerDetailPagination(GetSQLWhere(), pageNum, numPerPage, SQLSort, ref TotalCount);

            this.rpMenu.DataSource = dts[0];
            this.rpMenu.DataBind();

            SUMDT = dts[1];
        }


       
        protected string COldBack(object OInQuantity, object OneedbackQuantity)
        {
            decimal InQuantity = Convert.ToDecimal(OInQuantity);
            decimal needbackQuantity = Convert.ToDecimal(OneedbackQuantity);
            if (needbackQuantity <= 0)
                return "100%";

            return ((InQuantity / needbackQuantity) * 100).ToString("F2") + "%";
        }


        protected string GetUMDTValue(string filename)
        {
            if (SUMDT.Rows.Count <= 0)
            {
                return "0";
            }
            if (SUMDT.Rows[0][filename] is DBNull)
                return "0";
            return SUMDT.Rows[0][filename].ToString();
        }


    }
}